#ifndef CHOOSEFRIENDDIALOG_H
#define CHOOSEFRIENDDIALOG_H

#include <QCheckBox>
#include <QDialog>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPainter>
#include <QPushButton>
#include <QScrollArea>
#include <QScrollBar>
#include <QWidget>

#include "model/data.h"

class ChooseFriendDialog;

class ChooseFriendItem : public QWidget
{
    Q_OBJECT
  public:
    ChooseFriendItem(ChooseFriendDialog *owner, const QString &userId, const QIcon &avatar, const QString &name,
                     bool checked);

    void paintEvent(QPaintEvent *event) override;
    void enterEvent(QEnterEvent *event) override;
    void leaveEvent(QEvent *event) override;

    QString    getUserId() { return _userId; }
    QCheckBox *getCheckBox() { return _checkBox; }

  private:
    bool _isHover = false;

    QCheckBox          *_checkBox;
    QPushButton        *_avatarBtn;
    QLabel             *_nameLabel;
    ChooseFriendDialog *_owner;  // 负责记录哪个 QWidget 持有了这个 Item
    QString             _userId; // 负责记录当前 Item 对应的 userId
};

class ChooseFriendDialog : public QDialog
{
    Q_OBJECT
  public:
    ChooseFriendDialog(QWidget *parent, const QString &userId);
    void addFriend(const QString &userId, const QIcon &avatar, const QString &name, bool checked);
    void addSelectedFriend(const QString &userId, const QIcon &avatar, const QString &name);
    void deleteSelectedFriend(const QString &userId);

    void initLeft(QHBoxLayout *layout);
    void initRight(QHBoxLayout *layout);

  private:
    // 用于保存左侧全部好友列表
    QWidget *_totalContainer;
    // 用于保存右侧选中好友列表
    QWidget *_selectedContainer;
};

#endif // CHOOSEFRIENDDIALOG_H
